#coding=utf-8
import pymysql
conn = pymysql.connect(
                host='localhost',
                port=3306,
                user='root',
                passwd='root',
                db='webmagictest',
                charset='utf8',
            )
cur = conn.cursor()
with open("E:\\pythonTest\\mysql.txt", "r") as f:
    while True :
        line = f.readline().strip("\n")
        if line:
            print(line)
            l = line.split(",")
            print(l)
            username = l[0]
            password = l[1]
            cur.execute(
                    "insert into user(username,password) values(%s,%s)",
                    [username, password])
        else:
            break
    cur.close()
    conn.commit()
    conn.close()
print("插入成功")